<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>处理推送事件</title>
</head>
<body>
  <script>
    (async () => {
      const registration = await navigator.serviceWorker.register('./27_4_11_4_serviceWorker.js');
      // 请求显示通知的授权
      const status = await Notification.requestPermission();
      if (status === 'granted') {
        // 如果获得授权，只订阅推送消息
        registration.pushManager.subscribe({
          applicationServerKey: '<public-key>',  // 来自服务器的公钥
          userVisibleOnly: true
        });
      }
    })();
  </script>
</body>
</html>